<script>
import BaseEditForm from '../components/baseForm/edit';
export default {
    props: {

    },
    extends: BaseEditForm,
    data () {
        return {}
    },
    methods: {
        submit: function () {
            const { id, parentId, formName } = this;
            this.$f.validate((valid) => {
                if (valid) {
                    const formData = this.formatSubmitData(formName, this.$f.formData());
                    this.$x.put('/orginfo/orgOperation/orgUpdate', {
                        id,
                        parent_group_id: parentId,
                        data: formData
                    }).then(() => {
                        this.$message.success('编辑成功！');
                        this.$emit('listChanged')
                        this.$router.back();
                    });
                }
            });
        },
        fetchData: function () {
            const { formName, parentName } = this;
            this.$x.get('/orginfo/orgOperation/orgDetail', { id: this.id })
                .then(({ data }) => {
                    if (Object.keys(data).length === 0) {
                        this.$message.error('详情数据为空！');
                        return this.$router.back();
                    }
                    this.values = this.formatValues(formName, Object.assign({}, data, { parentName }));
                    this.ready = true;
                });
        }
    }
}
</script>
